#include <myhead.h>
#include "dao.h"
#include "mypkg.h"

void test_tbl_chat_friend(){
	for(int i=0;i<11;i++){
		spkg_chat_t t={1,"111","222","333",1,"2024-11-20 21:52:01",
			"hello world", 1};
		tbl_chat_friend_insert(&t);
	}
	getchar();
	spkg_chat_t arr[5];
	int arrLen=5;
	while(arrLen>0){
		tbl_chat_friend_select("222", arr, &arrLen);
		printf("读到了arrlen=[%d]条数据\n", arrLen);
		for(int i=0;i<arrLen;i++){
			printf("i=[%d],serial=[%d],source=[%s],dest=[%s],msgtime=[%s],msg=[%s],state=[%d]\n",
					i, arr[i].serial, arr[i].src, arr[i].dest, arr[i].msgtime, arr[i].msg, arr[i].state);
			tbl_chat_friend_delete(arr[i].serial);
		}
	}
}

int main(int argc, const char *argv[])
{
	tbl_dao_init();
	//
	char username[]="aaa";
	char friendname[]="bbb";
	//insert
	int ret=tbl_friend_insert(username, friendname, 1);
	printf("insert ret=[%d]\n", ret);
	//getState
	int state=-100;
	ret=tbl_friend_getState(username, friendname, &state);
	printf("getState, ret=[%d],state=[%d]\n", ret,state);
	//get
	getchar();
	spkg_user_t arr[5];
	int arrLen=5;
	ret=tbl_friend_getList("aaa", 1, arr, &arrLen);
	printf("ret=[%d], 读到了arrlen=[%d]条数据\n",ret, arrLen);
	for(int i=0;i<arrLen;i++){
		printf("i=[%d],username=[%s],friendname=[%s]\n",
				i, arr[i].username, arr[i].friendname);
	}
	//update
	ret=tbl_friend_updateState(username,friendname,0);
	printf("update: ret=[%d]\n", ret);
	//get
	getchar();
	arrLen=5;
	tbl_friend_getList("aaa", 1, arr, &arrLen);
	printf("读到了arrlen=[%d]条数据\n", arrLen);
	for(int i=0;i<arrLen;i++){
		printf("i=[%d],username=[%s],friendname=[%s]\n",
				i, arr[i].username, arr[i].friendname);
	}
	//getNum
	int num=tbl_friend_getNum("bbb", 0);
	printf("num=[%d]\n", num);
	

	return 0;
}

